package com.ningjingjing.api;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.ningjingjing.model.Album;
import com.ningjingjing.model.Story;
import com.ningjingjing.service.AlbumService;
import com.ningjingjing.util.DBUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

@WebServlet("/api/album-detail.json")
public class AlbumDetailApi extends AbsApiServlet {
    private final AlbumService albumService = new AlbumService();

    @Override
    protected Object doGetInner(HttpServletRequest req, HttpServletResponse resp) throws SQLException, ServletException, IOException, APIException {
        int aid = Integer.parseInt(req.getParameter("aid"));

        try (Connection c = DBUtil.getConnection()) {
            return albumService.get(c, aid);
        }
    }
}
